import axiosBase from '@/api/axios';
// const baseUrl = `${window.location.protocol}//${window.location.hostname}`;
import { webServiceUrl } from '@/api/baseURL';
export default {
  /**
   * @description: 上传文件
   * @param {Object}  *
   */
  uploadFile(upDownType, moduleType, file) {
    return axiosBase.post(`/common/file/upDown/upload?upDownType=${upDownType}&moduleType=${moduleType}`, file);
  },
  upload(upDownType, moduleType, data, otherOpt = {}) {
    return axiosBase({
      url: `/common/file/upDown/upload?upDownType=${upDownType}&moduleType=${moduleType}`,
      // url: `http://localhost:3000/api/upDown/upload?upDownType=${upDownType}&moduleType=${moduleType}`,
      method: 'post',
      data,
      ...otherOpt
    });
  },
  /**
   * @description: 根据fileid查询
   * @param {Object}  *
   */
  queryListById(upDownType, moduleType) {
    return axiosBase.post(`/common/file/upDown/queryListById?upDownType=${upDownType}&moduleType=${moduleType}`);
  },
  /**
   * @description: 上传文件并返回HttP地址
   * @param {Object}  *
   */
  getUploadUrl(upDownType, moduleType, file) {
    return axiosBase.post(`/common/file/upDown/getUploadUrl?upDownType=${upDownType}&moduleType=${moduleType}`, file);
  },
  /**
   * @description: 根据fileid查看
   * @param {Object}  *
   */
  viewFile(params) {
    return axiosBase.get(`/common/file/upDown/view?upDownType=${params.upDownType}&moduleType=${params.moduleType}&fileId=${params.fileId}`);
    // return axiosBase.get(`${baseUrl}:3000/api/upDown/view?upDownType=${params.upDownType}&moduleType=${params.moduleType}&fileId=${params.fileId}`);
  },
  getFileUrl(params) {
    return `${webServiceUrl}common/file/upDown/view?upDownType=${params.upDownType}&moduleType=${params.moduleType}&fileId=${params.fileId}`;
    // return `${baseUrl}:3000/api/upDown/view?upDownType=${params.upDownType}&moduleType=${params.moduleType}&fileId=${params.fileId}`;
  },
  getDownloadUrl(params) {
    return `${webServiceUrl}common/file/upDown/download?upDownType=${params.upDownType}&moduleType=${params.moduleType}&fileId=${params.fileId}`;
    // return `${baseUrl}:3000/api/upDown/download?upDownType=${params.upDownType}&moduleType=${params.moduleType}&fileId=${params.fileId}`;
  },
  /**
   * @description: 根据fileid播放
   * @param {Object}  *
   */
  viewVideo(params) {
    return axiosBase.get(`/common/file/upDown/videoView?upDownType=${params.upDownType}&moduleType=${params.moduleType}&fileId=${params.fileId}`);
  },
  /**
   * @description: 生成文件传输校验码
   * @param {Object}  *
   */
  generateKeyCode(params) {
    return axiosBase.get('/common/file/upDown/generateKeyCode', params);
  },
  /**
   * @description: 根据fileid下载
   * @param {Object}  *
   */
  downloadFile(params) {
    return axiosBase.get(`/common/file/upDown/download?upDownType=${params.upDownType}&moduleType=${params.moduleType}&fileId=${params.fileId}`);
  }
};
